package com.example.fw;

import java.io.File;

import autoitx4java.AutoItX;

import com.jacob.com.ComThread;
import com.jacob.com.LibraryLoader;

public class AutoItHelper extends HelpersBase{

	static{
		File jacob = new File("./lib/jacob-1.17-M2-x86.dll");
		System.setProperty(LibraryLoader.JACOB_DLL_PATH, jacob.getAbsolutePath());
	}

	private final AutoItX aux;
	private String winTitle;
	private String winText; 
	
	public AutoItHelper(ApplicationManager applicationManager) {
		super(applicationManager);
		ComThread.InitMTA();
		aux = new AutoItX();
	}

	public AutoItHelper winWaitAndActivate(String winTitle, String winText, int timeout){
		this.winTitle = winTitle;
		this.winText = winText;
		aux.winWait(winTitle, winText, timeout);
		aux.winActivate(winTitle, winText);
		aux.winWaitActive(winTitle, winText, timeout);
		return this;
	} 
	
	public AutoItHelper click(String controlId){
		aux.controlClick(winTitle, winText, controlId);
		return this;
	}
	
	public AutoItHelper focus(String controlId){
		aux.controlFocus(winTitle, winText, controlId);
		return this;
	}
	
	public AutoItHelper send(String text){
		aux.send(text, false);
		return this;
	}
	
	public AutoItHelper send(String controlId, String text){
		focus(controlId);
		aux.send(text, false);
		return this;
	}

	public String getText(String controlId) {
		return aux.controlGetText(winTitle, winText, controlId);
		
	}
}
